package com.demo.oauth2jFinalShiroServer.oauth2;

import org.apache.shiro.authc.AuthenticationToken;

import com.demo.oauth2jFinalShiroServer.cache.OAuth2EntityCache;
import com.demo.oauth2jFinalShiroServer.model.OAuth2Entity;

public class ResourceAccessToken implements AuthenticationToken {

	private String accessToken;

	public ResourceAccessToken(String accessToken) {
		super();
		this.accessToken = accessToken;
	}

	public ResourceAccessToken() {
		super();
	}

	@Override
	public Object getPrincipal() {
		OAuth2Entity oAuth2Entity = OAuth2EntityCache.TOKEN_OAUTH2_MAP.get(this.accessToken);
		return oAuth2Entity == null ? null : oAuth2Entity.getUsername();
	}

	@Override
	public Object getCredentials() {
		return this.accessToken;
	}

}
